<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <h2 v-loading="loading">Hello =&gt; <span class="ca">{{ user.account}}</span> &lt;=</h2>
    <ul>
      <li><router-link to="/limbo">里世界</router-link></li>
      <li><router-link to="/signin"> 登录 </router-link></li>
      <li><router-link to="/signup">注册</router-link></li>
      <li><el-button type="text" @click="signout">注销</el-button></li>
    </ul>
    <p>
      关于项目的一些快捷地址<br>
      <a href="https://cli.vuejs.org/zh/config/" target="_blank" rel="noopener">vue.config.js</a>  配置参考，修改后端代理可能需要.
    </p>
    <h3>Express相关的</h3>
    <ul>
      <li><a href="https://expressjs.com/zh-cn/" target="_blank" rel="noopener">Express Core</a></li>
    </ul>
    <h3>vuejs相关的</h3>
    <ul>
      <li><a href="https://vuejs.org" target="_blank" rel="noopener">Vue Core</a></li>
    </ul>
    <h3>相关组件</h3>
    <ul>
      <li><a href="https://element.eleme.cn/#/zh-CN" target="_blank" rel="noopener">前端组件</a></li>
      <li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
      <li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
      <li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
      <li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
      <li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  data() {
    return {
      user: {},
      loading: true
    }
  },
  methods: {
    signout() {
      let _self = this;
      _self.axios.delete(api.signout).then(resp => {
        if(200 == resp.data.code) {
          _self.whoami();
        } else {
          _self.$message.warning(resp.data.msg);
        }
      })
    },
    whoami() {
      let _self = this;
      _self.loading = true;
      this.axios.get(api.whoami).then(resp => {
        _self.user = resp.data.result;
        _self.loading = false;
      })
    }
  },
  mounted() {
    this.whoami()
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
.ca {
  cursor: pointer;
  text-decoration: underline;
  color: #42b983;
}
</style>
